package com.xiaozhijun;

import java.util.*;

public class P_20200529 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(getResult(new int[]{1, 2, 3, 2, 3, 4})));
        System.out.println(Arrays.toString(getResult(new int[]{4, 6, 7, 4, -1, -3, 4})));
        System.out.println(Arrays.toString(getResult(new int[]{1, 2, 3, 4})));
    }

    public static int[] getResult(int[] score) {
        int[] result = new int[2];
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < score.length; i++) {
            List<Integer> list;
            if (map.get(score[i]) == null) {
                list = new ArrayList<>();
            } else {
                list = map.get(score[i]);
            }
            list.add(i);
            map.put(score[i], list);
        }
        if (map.keySet().size() == score.length) {
            return new int[0];
        }
        int[] sum = new int[score.length];
        sum[0] = score[0];
        for (int i = 1; i < score.length; i++) {
            sum[i] = score[i] + sum[i - 1];
        }
        for (Integer key : map.keySet()) {
            List<Integer> list = map.get(key);
            if (list.size() <= 1) {
                continue;
            }
            int count = 0;
            for (int i = 0; i < list.size() - 1; i++) {
                for (int j = i + 1; j < list.size(); j++) {
                    int res = sum[list.get(j)] - sum[list.get(i)] + score[list.get(j)];
                    if (count < res) {
                        count = res;
                        result[0] = list.get(i);
                        result[1] = list.get(j);
                    }
                }
            }
        }
        return result;
    }
}
